package com.ambulance.project.manager.service.impl;

import java.util.List;

import com.ambulance.project.biz.entity.Hospital;
import com.ambulance.project.manager.utils.*;
import com.google.common.primitives.Longs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ambulance.project.manager.mapper.BizDepartMapper;
import com.ambulance.project.manager.domain.BizDepart;
import com.ambulance.project.manager.service.IBizDepartService;

/**
 * 科室Service业务层处理
 *
 * @author zr
 * @date 2020-05-11
 */
@Service
public class BizDepartServiceImpl implements IBizDepartService
{
    @Autowired
    private BizDepartMapper bizDepartMapper;
    @Autowired
    private MgtCommonUtil mgtCommonUtil;
    /**
     * 查询科室
     *
     * @param id 科室ID
     * @return 科室
     */
    @Override
    public BizDepart selectBizDepartById(Long id)
    {
        return bizDepartMapper.selectBizDepartById(id);
    }

    /**
     * 查询科室列表
     *
     * @param bizDepart 科室
     * @return 科室
     */
    @Override
    public List<BizDepart> selectBizDepartList(BizDepart bizDepart)
    {
        final MgtUserLoginResult mgtUserLoginResult = mgtCommonUtil.getMgtUserLoginResult();
        bizDepart.setUid(new Long(mgtUserLoginResult.getUid()));
        return bizDepartMapper.selectBizDepartList(bizDepart);
    }

    @Override
    public List<BizDepart> selectBizDepartList() {
        BizDepart bizDepart = new BizDepart();
        PadUserLoginResult padLoginUser = doctorAndNurseCommonUtil.getPadLoginUser();
        bizDepart.setUid(padLoginUser.getUid().longValue());
        List<BizDepart> departs = this.selectBizDepartList(bizDepart);
        return departs;
    }

    @Override
    public List<BizDepart> selectBizDepartListOnHelper() {
        Hospital mgtUserLoginResult = helperCommonUtil.getMgtUserLoginResult();
        Integer uid = mgtUserLoginResult.getUid();

        BizDepart bizDepart = new BizDepart();
        bizDepart.setUid(uid.longValue());
        List<BizDepart> departs = this.selectBizDepartList(bizDepart);
        return departs;
    }
    @Autowired
    private HelperCommonUtil helperCommonUtil;

    @Autowired
    private DoctorAndNurseCommonUtil doctorAndNurseCommonUtil;

    /**
     * 新增科室
     *
     * @param bizDepart 科室
     * @return 结果
     */
    @Override
    public int insertBizDepart(BizDepart bizDepart)
    {
        final MgtUserLoginResult mgtUserLoginResult = mgtCommonUtil.getMgtUserLoginResult();
        bizDepart.setUid(new Long(mgtUserLoginResult.getUid()));
        return bizDepartMapper.insertBizDepart(bizDepart);
    }

    /**
     * 修改科室
     *
     * @param bizDepart 科室
     * @return 结果
     */
    @Override
    public int updateBizDepart(BizDepart bizDepart)
    {
        return bizDepartMapper.updateBizDepart(bizDepart);
    }

    /**
     * 批量删除科室
     *
     * @param ids 需要删除的科室ID
     * @return 结果
     */
    @Override
    public int deleteBizDepartByIds(Long[] ids)
    {
        return bizDepartMapper.deleteBizDepartByIds(ids);
    }

    /**
     * 删除科室信息
     *
     * @param id 科室ID
     * @return 结果
     */
    @Override
    public int deleteBizDepartById(Long id)
    {
        return bizDepartMapper.deleteBizDepartById(id);
    }
}
